﻿// -----------------------------------------------------------------------
// <copyright file="IMessagesContract.cs" company="Spardo, LLC">
// Copyright (c) 2011 SPardo, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
// and/or sell copies of the Software, and to permit persons to whom the 
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
// </copyright>
// -----------------------------------------------------------------------

namespace DotNet37Signals.Client.Basecamp.Contracts
{
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using DotNet37Signals.Client.Basecamp.Models;
    using System;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    [ServiceContract]
    public interface IMessagesContract : IBasecampContract
    {
        [OperationContract]
        [WebGet(UriTemplate = "/projects/{projectId}/posts.xml")]
        Posts GetList(string projectId);

        [OperationContract]
        [WebGet(UriTemplate = "/posts/{postId}.xml")]
        Post Get(string postId);

        [OperationContract]
        [WebGet(UriTemplate = "/projects/{projectId}/cat/{categoryId}/posts.xml")]
        Posts GetListByCategory(string projectId, string categoryId);
            
        [OperationContract]
        [WebGet(UriTemplate = "/projects/{projectId}/posts/archive.xml")]
        Posts GetArchivedList(string projectId);

        [OperationContract]
        [WebGet(UriTemplate = "/projects/{projectId}/cat/{categoryId}/posts/archive.xml")]
        Posts GetArchivedListByCategory(string projectId, string categoryId);

        [OperationContract]
        [WebGet(UriTemplate = "/projects/{projectId}/posts/new.xml")]
        PostNew New(string projectId);

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/projects/{projectId}/posts.xml")]
        NewEntity Create(string projectId, PostNewRequest request);

        [OperationContract]
        [WebGet(UriTemplate = "/posts/{postId}/edit.xml")]
        PostNew Edit(string postId);

        [OperationContract]
        [WebInvoke(Method = "PUT", UriTemplate = "/posts/{postId}.xml")]
        void Update(string postId, PostNewRequest request);

        [OperationContract]
        [WebInvoke(Method = "DELETE", UriTemplate = "/posts/{postId}.xml")]
        void Delete(string postId);
    }

    public static class MessagesContractExtensions
    {
        public static Posts GetList(this IMessagesContract contract, Int64 projectId)
        {
            return contract.GetList(projectId.ToString());
        }

        public static Post Get(this IMessagesContract contract, Int64 postId)
        {
            return contract.Get(postId.ToString());
        }

        public static Posts GetListByCategory(this IMessagesContract contract, Int64 projectId, Int64 categoryId)
        {
            return contract.GetListByCategory(projectId.ToString(), categoryId.ToString());
        }

        public static Posts GetArchivedList(this IMessagesContract contract, Int64 projectId)
        {
            return contract.GetArchivedList(projectId.ToString());
        }

        public static Posts GetArchivedListByCategory(this IMessagesContract contract, Int64 projectId, Int64 categoryId)
        {
            return contract.GetArchivedListByCategory(projectId.ToString(), categoryId.ToString());
        }

        public static PostNew New(this IMessagesContract contract, Int64 projectId)
        {
            return contract.New(projectId.ToString());
        }

        public static NewEntity Create(this IMessagesContract contract, Int64 projectId, PostNewRequest request)
        {
            return contract.Create(projectId.ToString(), request);
        }

        public static PostNew Edit(this IMessagesContract contract, Int64 postId)
        {
            return contract.Edit(postId.ToString());
        }

        public static void Update(this IMessagesContract contract, Int64 postId, PostNewRequest request)
        {
            contract.Update(postId.ToString(), request);
        }

        public static void Delete(this IMessagesContract contract, Int64 postId)
        {
            contract.Delete(postId.ToString());
        }
    }
}
